<!--
* description: 国地补汇总表
* author: wangjuan
* createdDate: 2020-11-23
-->
<template>
  <div class="app-container app-container-table">
    <report-one-table
      ref="multipleTable"
      :key="oneTableKey"
      :dynamic-buttons="tableButtons"
      :dynamic-components="tableComponents"
      :dynamic-api-config="apiConfig"
      :dynamic-table-cols="tableCols"
      :dynamic-form-fields="formField"
      :dynamic-is-show-select="false"
      :dynamic-is-fix-index="false"
      :is-show-pagination="true"
    />
  </div>
</template>
<script>
import { oneTableWithViewTemplateMixins } from '@/components/mixins/oneTableWithViewTemplateMixins'
import Vue from 'vue'
import reportOneTable from '@/components/templates/reportoneTable'
import api from '@/api/subsidyManage'

export default {
  name: 'StateLandSubsidyAccountSchedule',
  components: {
    reportOneTable
  },

  // 组件混入对象：{data[listQuery] methods[queryTable]}
  mixins: [oneTableWithViewTemplateMixins],

  // 阻塞路由预加载网格中组件的数据
  beforeRouteEnter(to, from, next) {
    Vue.prototype.$ConfigCache.CacheConfig.initData([to.path, ''], function() {
      next()
    })
  },

  data() {
    // 页面标识（与上面beforeRouteEnter中的对应）
    const viewPageCode = this.$route.path

    // 绑定事件配置化事件
    this.$ConfigCache.CacheConfig.bindEvent(this, [viewPageCode])

    return {
      // 网格查询API配置对象
      apiConfig: api.querySummary,

      // 动态组件-按钮
      tableButtons: [
        {
          compKey: 'btnKey1',
          type: 'primary',
          size: 'small',
          name: 'search',
          clickEvent: () => this.queryTable(1),
          text: this.$t('sys.button.query'), // 查询
          position: 'right',
          fuzzySearch: true
        },
        {
          compKey: 'btnKey2',
          size: 'small',
          name: 'reset',
          clickEvent: () => this.reset(),
          text: this.$t('sys.button.reset'),
          position: 'right' // 重置
        }
      ],

      // 动态组件-查询条件
      tableComponents:
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path] &&
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path]
          .tableComponents &&
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path]
          .tableComponents.length > 0
          ? this.$ConfigCache.CacheConfig.cacheData[this.$route.path]
            .tableComponents
          : [
            // 显示组件
            {
              compKey: 'compKey1',
              labelName: '门店类别：',
              codeField: 'storeCategory',
              textField: 'storeCategory',
              lookuptype: 'VE1136',
              component: () => import('@/components/org/LookupValue'),
              type: 'dropdownList',
              isMul: false,
              isMust: true
            },
            {
              compKey: 'compKey2',
              labelName: '大区：',
              codeField: 'bigAreaName',
              textField: 'bigAreaName',
              component: () => import('@/components/org/LookupValue'),
              oFields: 'bigAreaId,bigAreaName',
              options: [
                { bigAreaId: '', bigAreaName: '' }
              ],
              type: 'dropdownList',
              isMul: false,
              isMust: true
            },
            {
              compKey: 'compKey3',
              labelName: '交付门店：',
              codeField: 'dlrShortName',
              component: () => import('./deliveryStore'),
              type: 'inputText',
              isMul: false,
              isMust: true
            }
          ],

      // 动态生成网格列
      tableCols:
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path] &&
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path].tableCols &&
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path].tableCols
          .length > 0
          ? this.$ConfigCache.CacheConfig.cacheData[this.$route.path].tableCols
          : [
            {
              prop: 'releaseId',
              label: '主键ID',
              hidden: true,
              alwaysHidden: true
            },
            {
              prop: 'updateControlId',
              label: '并发控制ID',
              hidden: true,
              alwaysHidden: true
            },
            {
              prop: 'storeCategory',
              label: '门店类别'
            },
            {
              prop: 'region',
              label: '大区'
            },
            {
              prop: 'store',
              label: '交付门店'
            },
            {
              prop: 'carDistribution',
              label: '门店配车数量'
            },
            {
              prop: 'invoice',
              label: '门店开票数量'
            },
            {
              prop: 'deliver',
              label: '门店交付数量'
            },
            {
              prop: '',
              label: '补贴资料',
              propsChildren: [
                {
                  prop: 'noim',
                  label: '未录入'
                },
                {
                  prop: 'onim',
                  label: '已录入'
                },
                {
                  prop: 'onplay',
                  label: '已申请'
                },
                {
                  prop: 'regionalPass',
                  label: '区域审核通过'
                },
                {
                  prop: 'regionalRejection',
                  label: '区域驳回'
                },
                {
                  prop: 'headquartersPass',
                  label: '总部审核通过'
                },
                {
                  prop: 'headquartersRejection',
                  label: '总部驳回'
                }
              ]
            }
          ],

      formField: this.$utils.getFormField(this, {
        storeCategory: '',
        bigAreaName: '',
        dlrCode: '',
        dlrShortName: ''
      }, this.$ConfigCache.CacheConfig.cacheData[viewPageCode])
    }
  },
  mounted() {
    // 列表查询
    this.queryTable(1)
    this.bigAreaSelectQuery()
  },

  methods: {
    // 大区下拉框
    bigAreaSelectQuery() {
      const bigAreaSelect = []
      const queryObj = {
        // api配置
        apiConfig: api.listOfRegion,
        // 表格中台返回网格的字段
        apiQueryRow: ['bigAreaId', 'bigAreaName'],

        // 条件/实体参数（变量），根据typeParam中的定义配置
        variables: this.formField
      }
      // 转换了中台请求格式数据
      var paramD = this.$getParams(queryObj)
      // 调用中台API方法（可复用）
      this.$requestAPI(paramD).then((response) => {
        if (response.result === '1') {
          const list = response.rows
          for (const k in list) {
            bigAreaSelect.push({
              bigAreaId: list[k].bigAreaId,
              bigAreaName: list[k].bigAreaName
            })
          }
          for (const k in this.tableComponents) {
            if (this.tableComponents[k].codeField === 'bigAreaName') {
              this.tableComponents[k].options = bigAreaSelect
              return false
            }
          }
        } else {
          this.$message({
            message: response.msg,
            type: 'warning',
            duration: 2000
          })
        }
      })
    }
  }
}
</script>
